<?php
namespace Admin\Controller;
use Think\Controller;

class GuestController extends Controller
{
	//连接数据库获取数据
	public function browse()
	{
		$guest = M('User');
        $count = $guest->count();
        $page = new \Think\Page($count,10);
        $show = $page->show();
        $list = $guest->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show);
    	$this->display();
    }


    //获取数据
    public function modify()
    {   
    	$id = $_GET['id'];
    	$obtain = M('User');
    	$user=$obtain->find($id);
    	$this -> assign('user',$user);
    	$this->display();
    }
    
    //更新是否禁用
    public function updata ()
    {
    	$id = $_GET['id'];
    	$data['status']=$_POST['status'];
    	$obtain = M('User');
    	$user=$obtain->where('id="'.$id.'"')->save($data);
    	if ($user) {
    		 if ($user) {
	    		$this->success('更新成功','./browse');
		    	}else{
		    		$this->error('更新失败');
		    	}
        }else{
              $this->success('提交成功','./browse');
    	}
    }


   //删除客户信息
    public function view(){
    	$id=$_GET['id'];
    	$data = M('User');
    	// echo $id;
    	$article=$data->where('id="'.$id.'"')->delete(); //删除数据//
    	if($article){
    		$this->success('删除成功');
    	}else{
    		$this->error('数据错误');
    	}
    }


    //关联address表"用户收货地址"
    public function details()
    {
      $id=$_GET['id'];
      $user = M('User');
      $data=$user->join('address on user.id=address.user_id')->where('user.id='.$id)->select();
      $this->assign('data',$data);
      $this->display();
    }

   

}